/*
 * Copyright 2009-2017 Alibaba Cloud All rights reserved.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <alibabacloud/elasticsearch/model/GetClusterDataInformationResult.h>
#include <json/json.h>

using namespace AlibabaCloud::Elasticsearch;
using namespace AlibabaCloud::Elasticsearch::Model;

GetClusterDataInformationResult::GetClusterDataInformationResult() :
	ServiceResult()
{}

GetClusterDataInformationResult::GetClusterDataInformationResult(const std::string &payload) :
	ServiceResult()
{
	parse(payload);
}

GetClusterDataInformationResult::~GetClusterDataInformationResult()
{}

void GetClusterDataInformationResult::parse(const std::string &payload)
{
	Json::Reader reader;
	Json::Value value;
	reader.parse(payload, value);
	setRequestId(value["RequestId"].asString());
	auto resultNode = value["Result"];
	if(!resultNode["connectable"].isNull())
		result_.connectable = resultNode["connectable"].asString() == "true";
	auto metaInfoNode = resultNode["metaInfo"];
	if(!metaInfoNode["settings"].isNull())
		result_.metaInfo.settings = metaInfoNode["settings"].asString();
	if(!metaInfoNode["mapping"].isNull())
		result_.metaInfo.mapping = metaInfoNode["mapping"].asString();
		auto allIndices = metaInfoNode["indices"]["indices"];
		for (auto value : allIndices)
			result_.metaInfo.indices.push_back(value.asString());
		auto allFields = metaInfoNode["fields"]["fields"];
		for (auto value : allFields)
			result_.metaInfo.fields.push_back(value.asString());
		auto allTypeName = metaInfoNode["typeName"]["typeName"];
		for (auto value : allTypeName)
			result_.metaInfo.typeName.push_back(value.asString());

}

GetClusterDataInformationResult::Result GetClusterDataInformationResult::getResult()const
{
	return result_;
}

